package com.mes.code.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.Formula;
import org.hibernate.annotations.GenericGenerator;

import com.mes.basicdata.domain.ClassInformation;
//import com.mes.basicdata.extend.domain.Attribute;
import com.mes.common.domain.BasicModel;


/*import com.mes.basicdata.persistence.domain.ClassInformation;
import com.mes.basicdata.persistence.domain.extend.Attribute;*/
@Entity()
//@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name = "C_CODERULE")
@BatchSize(size=10)
//@Lazy(value=true)
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class CodeRule extends BasicModel implements Serializable {
	public final static String CLASS_PREFIX_NAME = "分类=";
	public final static String CLASS_CODE_TYPE = "4";
	public final static String FEATURE_CODE_TYPE = "1";
	public final static String CONSTANT_CODE_TYPE = "0";
	public final static String PARAMETER_CODE_TYPE = "2";
	public final static String SERIALNUMBER_CODE_TYPE = "3";
	public final static String DATE_CODE_TYPE = "5";
	
	@Id
	@GenericGenerator(name = "crUid", strategy = "assigned")
	@Column(name = "CRUID")
	private String crUid;
	
	@Override
	public String getUuid() {
		return crUid;
	}

	@Override
	public void setUuid(String uuid) {
		this.crUid = uuid;
	}
	
	public String getCrUid() {
		return crUid;
	}

	public void setCrUid(String crUid) {
		this.crUid = crUid;
	}

	
	

	// Fields
	@Column(name="CRNAME",length=100)
	private String codeRuleName;
	
	@Column(name="CODETYPE",length=50)
	private String codeType;
	
	@Column(name="CLASS_UID",length=50)
	private String classUid;
	
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="CLASS_UID",insertable=false,updatable=false)
	private ClassInformation classInformation;
	
	@Column(name="SEQUENCE",length=50)
	private Integer sequence;
	
	@Column(name="CODELENGTH",length=50)
	private Integer codeLength;
	
	@Column(name="CODEREPLACER",length=50)
	private String codeReplacer;
	
	@Column(name="CODESTRING",length=50)
	private String codeString;
	
	@Column(name="CODEFORMAT",length=50)
	private String codeFormat;
	
	@Column(name="ATTRIBUTE_UID",length=50)
	private String attributeUid;
	
//	//many-to-one
//	@ForeignKey(name="null")
//	@ManyToOne(fetch=FetchType.LAZY)
//	@JoinColumn(name="ATTRIBUTE_UID",insertable=false,updatable=false)
//	private Attribute attribute;

	@Formula("(select types.iddesc from b_typesdata types where types.typesname = 'code_type' and types.id = CODETYPE)")
	private String codeTypeIddesc;
	
	
	@Column(name="CREATTIME",length=6)
	private Date creatTime;
	
	//其缺省对应的序列号
	@Transient
	private SerialNumber serialNumber;
	
	@Transient
	private Set<SerialNumberFeature> serialNumberFeatures;






	public Date getCreatTime() {
		return creatTime;
	}

	public void setCreatTime(Date creatTime) {
		this.creatTime = creatTime;
	}

	public SerialNumber getSerialNumber() {
		return serialNumber;
	}

	public void setSerialNumber(SerialNumber serialNumber) {
		this.serialNumber = serialNumber;
	}

	public Set<SerialNumberFeature> getSerialNumberFeatures() {
		return serialNumberFeatures;
	}

	public void setSerialNumberFeatures(
			Set<SerialNumberFeature> serialNumberFeatures) {
		this.serialNumberFeatures = serialNumberFeatures;
	}

	public String getCodeRuleName() {
		return codeRuleName;
	}

	public void setCodeRuleName(String codeRuleName) {
		this.codeRuleName = codeRuleName;
	}

	public String getCodeType() {
		return codeType;
	}

	public void setCodeType(String codeType) {
		this.codeType = codeType;
	}

	public Integer getSequence() {
		return sequence;
	}

	public void setSequence(Integer sequence) {
		this.sequence = sequence;
	}



	public Integer getCodeLength() {
		return codeLength;
	}

	public void setCodeLength(Integer codeLength) {
		this.codeLength = codeLength;
	}

	public String getCodeReplacer() {
		return codeReplacer;
	}

	public void setCodeReplacer(String codeReplacer) {
		this.codeReplacer = codeReplacer;
	}

	public String getCodeString() {
		return codeString;
	}

	public void setCodeString(String codeString) {
		this.codeString = codeString;
	}

	public String getCodeFormat() {
		return codeFormat;
	}

	public void setCodeFormat(String codeFormat) {
		this.codeFormat = codeFormat;
	}



	public String getClassUid() {
		return classUid;
	}

	public void setClassUid(String classUid) {
		this.classUid = classUid;
	}

	public ClassInformation getClassInformation() {
		return classInformation;
	}

	public void setClassInformation(ClassInformation classInformation) {
		this.classInformation = classInformation;
	}

	public String getAttributeUid() {
		return attributeUid;
	}

	public void setAttributeUid(String attributeUid) {
		this.attributeUid = attributeUid;
	}

//	public Attribute getAttribute() {
//		return attribute;
//	}
//
//	public void setAttribute(Attribute attribute) {
//		this.attribute = attribute;
//	}

	public String getCodeTypeIddesc() {
		return codeTypeIddesc;
	}

	public void setCodeTypeIddesc(String codeTypeIddesc) {
		this.codeTypeIddesc = codeTypeIddesc;
	}

}